package zack.project.domain.strategy.model.entity;

import zack.project.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {
    /** 抽奖策略ID*/
    private Long strategyId;
    /** 抽奖策略描述*/
    private String strategyDesc;
    /** 规则模型，rule配置的模型同步到此表，便于使用*/
    private String ruleModels;

    public String[] ruleModels(){
        if(StringUtils.isBlank(ruleModels)){
            return null;
        }
        return ruleModels.split(Constants.SPLIT);
    }
    //处理在{strategy}表中查询到的rule_models
    //id    strategy_id     strategy_desc       rule_models
    //4	    100004	        抽奖策略-随机抽奖		                        2023-12-09 09:37:19	2024-01-20 19:21:03
    //5	    100005	        抽奖策略-测试概率计算		                    2023-12-09 09:37:19	2024-01-21 21:54:58
    //6	    100006	        抽奖策略-规则树	    rule_blacklist,rule_weight	2024-02-03 09:53:40	2024-05-03 09:02:38
    public String getRuleWeight(){
        String[] ruleModels = this.ruleModels();
        if (null == ruleModels) return null;
        for(String ruleModel : ruleModels){
            if("rule_weight".equals(ruleModel)){
                return ruleModel;
            }
        }
        return null;
    }
}
